package face.pay.web.com.applyment.wx;

import face.pay.common.enterprise.service.IWeChatMchInfoService;
import face.pay.entity.UserInfo;
import face.pay.entity.WeChatMchInfo;
import face.pay.system.annotation.CurrentUser;
import face.pay.system.exception.BaseException;
import face.pay.util.ResultMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/wxmchinfo")
public class WxMchInfoController {

    @Autowired
    IWeChatMchInfoService iWeChatMchInfoService;

    @RequestMapping("/index")
    public  String index(@CurrentUser UserInfo loginUser, Integer mchUserId, Model model){

         Integer mcId= mchUserId==null?loginUser.getId():mchUserId;

        WeChatMchInfo weChatMchInfo =  iWeChatMchInfoService.getByUserId(mcId);
        if(weChatMchInfo==null){
            weChatMchInfo =  new WeChatMchInfo();
            weChatMchInfo.setUserId(mchUserId);
            this.iWeChatMchInfoService.insert(weChatMchInfo,loginUser);
            /**
             * 新增进件资料
             */
        }
        model.addAttribute("weChatMchInfo",weChatMchInfo);

        return "agency/enterprise/applyment/wechat_mch_info";
    }


    @RequestMapping("/edit")
    @ResponseBody
    public ResultMessage editUser(@CurrentUser  UserInfo loginUser, WeChatMchInfo weChatMchInfo) throws BaseException {

        return iWeChatMchInfoService.modifyInfo(weChatMchInfo,loginUser);

    }
}
